<template>
    <div>
        <city-header></city-header>
        
        <div class="cityLeftContent">
            <cityLeft-contentOne :option="option" :weatherList="weatherList" :CityEPAdata="CityEPAdata" :AllCityAqi="AllCityAqi"></cityLeft-contentOne>
            <cityLeft-contentTwo></cityLeft-contentTwo>
            <cityLeft-contentThree :QXZS="QXZS"></cityLeft-contentThree>   
        </div>
        <right-tool></right-tool>
        <common-bottom></common-bottom>
        <city-centerContent :CityEPAdatas24h="CityEPAdatas24h" :CityEPAdatas7Day="CityEPAdatas7Day" :AllCityAqis24h="AllCityAqis24h" :AllCityAqis7Day="AllCityAqis7Day" ></city-centerContent>
        <city-stationCount :getStationCountData="getStationCountData" :StationQXDJCounts="StationQXDJCounts" :CityEPAdata="CityEPAdata"></city-stationCount>
        <common-controlBtn></common-controlBtn>
        <cesium-containerc :newArr2 ="newArr2" :newArr4="newArr4"></cesium-containerc>
    </div>
</template>
<script>
import CesiumContainerc from '../cesium/CesiumContainerc'
import CityHeader from './components/CityHeader'
import RightTool from '../commons/RightTool'
import CityLeftContentOne from './components/CityLeftContentOne'
import CityLeftContentTwo from './components/CityLeftContentTwo'
import CityLeftContentThree from './components/CityLeftContentThree'
import CityCenterContent    from './components/CityCenterContent'
import CommonBottom from '../commons/CommonBottom'
import CityStationCount from './components/CityStationCount'
import CommonControlBtn from './components/CommonControlBtn'
import axios from 'axios'
export default {
    name: 'City',
    data(){
        return{
            timer:null,
            newArr2:[],
            newArr4:[],
            weatherList: null,
            city_code: '',
            timer: null,
            CityEPAdata:{},
            getStationCountData:[],
            QXZS:{},
            AllCityAqi:null,
            StationQXDJCounts:[],
            AllCityAqis24h:[],
            AllCityAqis7Day:[],
            CityEPAdatas24h:[],
            CityEPAdatas7Day:[],
            x:null,
            dingwei:'dw'
        }
    },
    watch: {
        city_code: function(){
            this.getWeather()
        },
        x:(val)=>{
            console.log(val)
        }
    },
    
    components: {
        CesiumContainerc,
        CityHeader,
        RightTool,
        CityLeftContentOne,
        CityLeftContentTwo,
        CityLeftContentThree,
        CommonBottom,
        CommonControlBtn,
        CityCenterContent,
        CityStationCount
    },
    created(){
       this.$store.commit("changeForq",0)
    },
    mounted(){
        //this.$comjs.onCenter(119.906064,29.573401,961893.0);
        
        this.getCityCode();
        this.getCityData();
        var date = new Date();//现在时刻
        var dateIntegralPoint = new Date();//用户登录时刻的下一个整点，也可以设置成某一个固定时刻
        dateIntegralPoint.setHours(date.getHours()+1);//小时数增加1
        dateIntegralPoint.setMinutes(10);
        dateIntegralPoint.setSeconds(0);
        console.log(dateIntegralPoint);
        console.log(dateIntegralPoint-date);
        console.log((dateIntegralPoint-date)/60000);
        setTimeout(()=>{this.andUpdata()},dateIntegralPoint-date);//用户登录后的下一个整点执行。
    },
    
    beforeDestroy(){
        if(this.timer){
          clearInterval(this.timer)
        }
    },
    methods: {
        getCityCode(){
            axios.get('/_city.json').then(
                (res) =>{
                    var nameCode = res.data
                    for(var i=0;i<nameCode.length;i++){
                        if(nameCode[i].city_name == this.$route.params.name.trim()){
                            this.city_code = nameCode[i].city_code
                        }
                    }
                }
            )
        },
        getWeather(){
            console.log(this.city_code)
            axios.get('/api'+ this.city_code).then(
                this.getWeatherInfo
            )
            
        },
        getWeatherInfo(res){
            setTimeout(()=>{
                 this.weatherList = res.data;
            },300)
        },
        getCityData(){
            if(this.$comjs.isOnline){
                axios.get('/apis/api/FYLZ/GetFYLZCityInfo?city='+ this.$store.state.headerCity).then(
                    this.getCityDataInfo
                ) 
            }else{
                axios.get(this.$comjs.fylzCity).then(
                    this.getCityDataInfo
                )
            }
           
            
        },
        getCityDataInfo(res){
            if(res.data.CityEPAdata){
                this.CityEPAdata=res.data.CityEPAdata;
                this.$store.commit('getFYLZC',this.CityEPAdata)
                this.x = res.data.CityEPAdata.Lon;
                if(this.dingwei=='dw'){
                    this.$comjs.onCenter(res.data.CityEPAdata.Lon,res.data.CityEPAdata.Lat,360000.0);
                }
                this.$store.commit('changeCityX',res.data.CityEPAdata.Lon)
                this.$store.commit('changeCityY',res.data.CityEPAdata.Lat)
            }
            if(res.data.StationTypeCounts){
                this.getStationCountData=res.data.StationTypeCounts;  
            }
            if(res.data.QXZS){
                this.QXZS=res.data.QXZS;
            }
            if(res.data.AllCityAqi){
                this.AllCityAqi=res.data.AllCityAqi;  
                this.$store.commit('getFYLZAll',this.AllCityAqi);
            }
            if(res.data.StationQXDJCounts){
                this.StationQXDJCounts=res.data.StationQXDJCounts; 
            }
            if(res.data.AllCityAqis24h){
                this.AllCityAqis24h=res.data.AllCityAqis24h; 
            }
            if(res.data.AllCityAqis7Day){
                this.AllCityAqis7Day=res.data.AllCityAqis7Day;
            }
            if(res.data.CityEPAdatas24h){
                this.CityEPAdatas24h=res.data.CityEPAdatas24h;
            }
            if(res.data.CityEPAdatas7Day){
                 this.CityEPAdatas7Day=res.data.CityEPAdatas7Day;  
            }
            if(res.data.CountryStationQXDJCounts){
                this.$store.commit('getCountryStationQXDJCounts',res.data.CountryStationQXDJCounts)
            }
            if(res.data.Regions){
                this.$store.commit("changeCounty",res.data.Regions)
            }
            if(res.data.StationEPAdatas){
                this.newArr2 = res.data.StationEPAdatas;
            }
            if(res.data.CountryEPAdatas){
                this.newArr4 = res.data.CountryEPAdatas;
            }
            
        },
        // getStationCount(){           
        //     axios.get('/FYLZCity.json').then(
        //         this.getStationCountInfo
        //     )
        // },
        // getStationCountInfo(res){
        //     this.getStationCountData=res.data.StationTypeCounts;  
        //     this.QXZS=res.data.QXZS;
        // },
        andUpdata(){
            this.dingwei='bdw';//不重新定位
            this.getCityData()//在整点执行的函数，在每个整点都调用该函数
            this.timer = setInterval(()=>{this.getCityData()},60*60*1000);//一个小时执行一次，那么下一个整点，下下一个整点都会执行
        }
    }
}
</script>
<style scoped>
    .cityLeftContent{
        position: absolute;
        left: 0;
        top: 6.57vh;
        z-index: 2;
        width: 4.02rem;
        height: calc(100% - 12.3vh); 
        /* height: 87.7vh; */
        /* overflow: hidden */
    }
</style>

